<?php

class OutletLog
{

  public static $ENABLED = false;

  protected static $started = false;

  public static function log($data)
  {
    if (!self::$ENABLED) return;
    
    //ob_start();
    
    if (is_a($data, 'PDOStatement')) {
      //echo preg_replace('/\r?\n/', '', trim($data->queryString));
      sy_log('outlet', preg_replace(array('/\r?\n/', '/ +/'), array(' ', ' '), trim($data->queryString)));
    }
    
    //self::write(ob_get_clean());
  }

  protected static function write($string)
  {
    if (!self::$ENABLED) return;
    
    if (! self::$started) {
      self::$started = true;
      self::start();
    }
    
    $s = @file_get_contents(self::file());
    $s .= Simplify::getRequest()->get('route') . "\n\n";
    $s .= $string . "\n\n";
    @file_put_contents(self::file(), $s);
  }

  protected static function start()
  {
    if (!self::$ENABLED) return;
    
    self::write(str_repeat('-', 30) . ' ' . date('Y-m-d h:i:s') . ' ' . str_repeat('-', 30));
  }

  protected static function file()
  {
    return Simplify::getConfig()->get('app_dir') . '/outlet_log.txt';
  }

}

?>